package com.seven.first.ms.base;

import com.github.pagehelper.PageInfo;
import com.seven.first.suite.base.BaseDTO;
import com.seven.first.suite.base.BasePO;
import com.seven.first.suite.base.QueryDTO;
import com.seven.first.suite.result.ApiResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public abstract class AbstractBaseController<PO extends BasePO, DTO extends BaseDTO, QUERY extends QueryDTO> extends BaseController {


    public abstract BaseService<PO, DTO, QUERY> baseService();

    @PostMapping("/page")
    public ApiResult<PageInfo<DTO>> page(@RequestBody QUERY query) {
        return this.baseService().selectDTOPage(query);
    }

    @PostMapping("/add")
    public ApiResult<DTO> add(@RequestBody DTO dto) {
        return this.baseService().insertDTO(dto);
    }

    @PostMapping("/update/selective")
    public ApiResult<DTO> updateByPrimaryKeySelective(@RequestBody DTO dto) {
        return this.baseService().updateByPrimaryKeySelective(dto);
    }

    @PostMapping("/update")
    public ApiResult<DTO> update(@RequestBody DTO dto) {
        return this.baseService().updateDTO(dto);
    }

    @PostMapping("/delete")
    public ApiResult<Integer> deleteLogicallyByIds(@RequestBody List<Long> ids) {
        return this.baseService().deleteLogicallyByIds(ids);
    }

    @PostMapping("/recovery")
    public ApiResult<Integer> recoveryLogicallyByIds(@RequestBody List<Long> ids) {
        return this.baseService().recoveryLogicallyByIds(ids);
    }
}
